<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul>

    </ul>
    <script type="text/javascript">
        var oUl = document.getElementsByTagName('ul')[0];
        // 创建一个文档碎片来存放要生成的元素，提升性能
        var oFrag = document.createDocumentFragment();
        for (var i = 0; i < 10; i++) {
            var oLi = document.createElement('li');
            oLi.innerText = '列表第' + (i + 1) + '项';
            (function(i){
                oLi.onclick = function(){
                    this.innerText = i+1;
                }
            })(i);
            oFrag.appendChild(oLi);
        }
        oUl.appendChild(oFrag);

    </script>
</body>

</html>